﻿@using Entidades.Sistema.Base;
@using Entidades.Sistema.Distribucion;
@using System.Collections.ObjectModel;

@{
    Html.EnableClientValidation(false);
    Html.EnableUnobtrusiveJavaScript(false);

    var grid = Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "gvEditing";
            settings.KeyFieldName = "IdDiagramacionDistribucion";
            settings.CallbackRouteValues = new { Controller = "DiagramacionDistribucion", Action = "EditDiagramacionDistribucionPartial" };

            settings.Columns.Add(column =>
            {
                column.Caption = "#";
                column.SetDataItemTemplateContent(c =>
                {
                    var estado = DataBinder.Eval(c.DataItem, "Estado").ToString();
                    
                    //Agregar con un list
                    if (estado != "Cancelada" && estado != "Finalizada")
                    {
                        if (ViewBag.PermisoEdit)
                        {
                            ViewContext.Writer.Write(

                            Html.ActionLink("Editar", "EditDiagramacionDistribucionUpdatePartial", new { IdDiagramacionDistribucion = DataBinder.Eval(c.DataItem, "IdDiagramacionDistribucion") }) + "&nbsp;"
                            );
                        }
//                        if (ViewBag.PermisoDelete)
//                        {
                            ViewContext.Writer.Write(

                            Html.ActionLink("Cancelar", "EditDiagramacionDistribucionDeletePartial", new { IdDiagramacionDistribucion = DataBinder.Eval(c.DataItem, "IdDiagramacionDistribucion") },
                                new { onclick = "return confirm('Realmente quiere cancelar la Diagramacion de Produccion?')" }));
 //                       }                    
                    }                    

                });
                column.SetHeaderTemplateContent(c =>
                {
                    if (ViewBag.PermisoCreate)
                    {
                        ViewContext.Writer.Write(
                        Html.ActionLink("Nuevo", "EditDiagramacionDistribucionUpdatePartial", new { IdDiagramacionDistribucion = -1 }).ToHtmlString());                    
                    }                    
                });

                
                column.Settings.AllowDragDrop = DefaultBoolean.False;
                column.Settings.AllowSort = DefaultBoolean.False;
                column.Width = 70;
            });

            settings.Columns.Add(columnImprimir =>
            {
                columnImprimir.SetDataItemTemplateContent(c =>
                {
                    var estado = DataBinder.Eval(c.DataItem, "Estado").ToString();

                    if (estado != "Cancelada")
                    {
                        ViewContext.Writer.Write(
                        Html.ActionLink("Imprimir", "ImprimirDiagramacion", new { IdDiagramacionDistribucion = DataBinder.Eval(c.DataItem, "IdDiagramacionDistribucion") },
                                new { onclick = "return confirm('Realmente quiere imprimir la diagramación?')" }));
                    }
                });
                columnImprimir.Settings.AllowDragDrop = DefaultBoolean.False;
                columnImprimir.Settings.AllowSort = DefaultBoolean.False;
            });

            settings.Columns.Add(columnConfirmar =>
            {
                columnConfirmar.SetDataItemTemplateContent(c =>
                {
                    var estado = DataBinder.Eval(c.DataItem, "Estado").ToString();

                    if (estado == "Creado" )
                    {
                        ViewContext.Writer.Write(
                        Html.ActionLink("Confirmar", "ConfirmarEntrega", new { IdDiagramacionDistribucion = DataBinder.Eval(c.DataItem, "IdDiagramacionDistribucion") },
                                new { onclick = "return confirm('Realmente quiere confirmar la entrega?')" }));
                    }
                });
                columnConfirmar.Settings.AllowDragDrop = DefaultBoolean.False;
                columnConfirmar.Settings.AllowSort = DefaultBoolean.False;
                columnConfirmar.Width = 70;
            });             
            
            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 800;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
            settings.SettingsPager.FirstPageButton.Visible = true;
            settings.SettingsPager.LastPageButton.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };
            
            
            settings.Settings.ShowFilterRow = true;
            settings.Settings.ShowFilterRowMenu = true;
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowClearFilterButton = true;
            
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.Columns.Add("IdDiagramacionDistribucion");
            settings.Columns.Add("Fecha");
            settings.Columns.Add("Estado");

            settings.PreRender = (s, e) =>
            {
                var sender = (MVCxGridView)s;
                sender.FocusedRowIndex = 0;
            };
            
            settings.SettingsBehavior.AllowFocusedRow = true;
        });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()














